﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RN.Entidades;
using RN.Componentes;

namespace Sitio
{
    public partial class WebFormSubArea : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (this.Session["usuario"] == null)
                {
                    Response.Redirect("Login.aspx");
                }
                Cargar_grid();
            }
            List<Areas> f = CArea.Traer();
            DropDownList1.DataSource = f;
            DropDownList1.DataTextField = "SNOMBRE_AREA1";
            DropDownList1.DataValueField = "LAREAS_ID1";
            DropDownList1.DataBind();
        }
        public void Cargar_grid()
        {
            List<SubAreas> obj = CSubarea.Traer();
            grdCentroDeCosto.DataSource = obj;
            grdCentroDeCosto.DataBind();
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(TextBox1.Text))
            {
                SubAreas sb = new SubAreas();
                sb.SNOMBRE1 = TextBox1.Text;
                sb.LAREAS_ID2.LAREAS_ID1 = Convert.ToInt32(DropDownList1.SelectedValue.ToString());
               
                if (CSubarea.Insertar(sb))
                {
                    Label1.Text = "se inserto correctamente";
                    Cargar_grid();
                    TextBox1.Text = "";
                }
                else { Label1.Text = "error al insertar"; }
            }
            else { Label1.Text = "escriba un nombre"; }
        }
        public void ResultGrid_RowCommand(object sender, GridViewCommandEventArgs e)
        {
        
        }

        protected void grdCentroDeCosto_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("./Principal.aspx");
        }
    }
}